﻿using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Globalization;
using ToolBoxPro;
using LinqObj;


public partial class login : System.Web.UI.Page
{
    private ServiceListBuilder sc = new ServiceListBuilder();

    protected void Page_Load(object sender, EventArgs e)
    {
        txt_user_name.Focus();
        Session.Timeout = 500;
    }

    protected void bt_login_Click(object sender, ImageClickEventArgs e)
    {        
        Toolbox_User _user = Toolbox_User.GetUserRef(txt_user_name.Text.Trim(), txt_password.Text.Trim());

        if (_user != null && _user.user_id > 0)
        {
            Session[FormContract.USER] = _user;
            Agent _agent = _user.Agent;

            if (_agent != null && _agent.agent_id > 0)
            {
                //Session["txtusername"] = txt_user_name.Text.Trim();
                //Session["txtpass"] = txt_password.Text.Trim();

                if (_agent.agent_group_id.HasValue)
                    ServiceListBuilder.AgentGroupID = _agent.agent_group_id.Value;
                else
                    ServiceListBuilder.AgentGroupID = 0;

                    Session[FormContract.AGENT_GROUP_ID] = _agent.agent_group_id;
                Session[FormContract.AGENT] = _agent;
                Response.Redirect("~/propertylist.aspx", false);
            }
        }
    }
}
